﻿using DotNetCore.CAP;
using Seagull.Extensions.ServiceBus;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class BusOptionsExtensions
    {
        /// <summary>
        /// 添加延时队列功能
        /// 必须在RabbitMQ 安装 delay-exchange 插件
        /// </summary>
        /// <param name="options">CapOptions 配置项</param>
        /// <returns></returns>
        public static CapOptions UseDelayQueue(this CapOptions options)
        {
            return options.UseDelayQueue(opt => { });
        }
        /// <summary>
        /// 添加延时队列功能
        /// 必须在RabbitMQ 安装 delay-exchange 插件
        /// </summary>
        /// <param name="options">CapOptions 配置项</param>
        /// <param name="configure">DelayOptions 配置项</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static CapOptions UseDelayQueue(this CapOptions options, Action<DelayOptions> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            options.RegisterExtension(new DelayCapOptionsExtension(configure));

            return options;
        }
    }
}
